$(function(){
    var
        oUseNameIp  = $('#useName'),
        oUseP1      = $('.use .p1'),
        oPassWardIp = $('#passWard'),
        oUseP2      = $('.use .p2'),
        oHZD        = $('.use .HZD'),
        oD    = $('.use .HZD .D'),
        oM    = $('.use .HZD .M'),
        oH    = $('.use .HZD .H');
    /*  判断用户名输入*/
    oUseNameIp.focus(function(){
        if (oUseNameIp.val()=='手机号/邮箱'){
            oUseNameIp.val('');
        }
    });
    oUseNameIp.blur(function(){
        if(oUseNameIp.val()==''||oUseNameIp.val()=='手机号/邮箱'){
            oUseP1.css({display:'block'})
        }
        var reg1=/(^1[34578]\d{9}$)|(^\w+@\w\.[a-zA-Z]{2,3}$)/;
        if(reg1.test(oUseNameIp.val())==false){
            oUseP1.css({display:'block'});
        }
    });
    //密码框获得焦点
    oPassWardIp.focus(function(){
        oPassWardIp.attr({placeholder:''})
    });
    //输入时下面p div 显示
    oPassWardIp.bind('input propertychange', function() {               //bind('input propertychange', function() {
        oHZD.css({display:'block'});
        var reg1=/\w{1,6}/;
        if(reg1.test(oPassWardIp.val())){
            oUseP2.html('密码长度不能少于六位');
        }
        var reg2=/\w{6,20}/;
        if(reg2.test(oPassWardIp.val())){
            oUseP2.html('密码较弱，建议设置多种字符组成的复杂密码')
        }
        //密码判断输入是否正确

        //判断输入是数字字母或者特殊字符
        var reg3=/([a-zA-Z]{1,20})|([\d]{1,20})|([@#$_ /\\%^&*()-+|?><!,.:;'"~`]{1,20})/;
        if(reg3.test(oPassWardIp.val())){
            oD.css({background:'rgb(0, 0, 0)'})
        }


        var reg5=/(([a-zA-Z]{1,})([@#$_ /\\%^&*()-+|?><,.:;'"~`]{1,}))/;
        var reg7=/((\d{1,})([@#$_ /\\%^&*()-+|?><,.:;'"~`]{1,}))/;
        var reg8=/((\d{1,})([a-zA-Z]{1,}))/;
        if(reg8.test(oPassWardIp.val()) || reg5.test(oPassWardIp.val()) || reg7.test(oPassWardIp.val())){
            oD.css({background:'rgb(0, 0, 0)'});
            oM.css({background:'rgb(0, 0, 0)'});
        }

        var reg4=/\d{1,}[a-zA-Z]{1,}[@#$%^&*()_\+\|\-\=\\,./;':"]{1,}/;
        if(reg4.test(oPassWardIp.val())){
            oD.css({background:'rgb(0, 0, 0)'});
            oM.css({background:'rgb(0, 0, 0)'});
            oH.css({background:'rgb(0, 0, 0)'})
        }
        //密码最多输入20个字符串
        var reg6=/\w{20,}/;
        if(reg6.test(oPassWardIp.val())){
           return false
        }
    });
    var
        oOkPass = $('#okPass'),
        oP3     = $('.use .p3');

    oOkPass.blur(function(){
        if(oOkPass.val()!=oPassWardIp.val()){
            oP3.css({display:'block'});
        }
    })

    //验证码
    var
        oYanZanIp = $('.yanZh>input'),
        oYanZanTS = $('.yanZh .tiShi a'),
        oYanZanTSImg = $('.tiShi img'),
        arr =[0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','F','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'],
        arr1=[];
    oYanZanTS.ready(function(){
        arr1=[];
        for(var i=0;i<4;i++){
            var aIndex = parseInt(Math.random()*52);
            arr1.push(arr[aIndex]);
        }
        oYanZanTS.html(arr1);
    });
    oYanZanTS.click(function(){
        //var aIndex = parseInt(Math.random()*12);
        //oYanZanTSImg.attr('src',arr[aIndex])
        arr1=[];
        for(var i=0;i<4;i++){
            var aIndex = parseInt(Math.random()*52);
            arr1.push(arr[aIndex]);
        }
        oYanZanTS.html(arr1);
    });

    //radio
    var
        oEm      = $('.f-bottom em'),
        oFlag    = true,
        oCommenRegisterA1 = $('.commen-register .a1'),
        oCommenRegisterA2 = $('.commen-register .a2');
    oEm.click(function(){
        if(oFlag){
            oEm.css({backgroundImage:"url('../images/icon_not_selected.png')"});
            oFlag=false;
        }else {
            oEm.css({backgroundImage: "url('../images/icon_selected.png')"});
            oFlag=true;
        }
    });



    var
        oAtiShi  = $('.DuanXin .tiShi'),
        oDuanXinaa1 = $('.DuanXin .aa1'),
        oDuanXinaa1Em = $('.DuanXin .aa1 em'),
        oDuanXinaa2 = $('.DuanXin .aa2'),
        oBtn1 = true;


        oAtiShi.click(function(){
            if(oUseNameIp.val()==''||oUseNameIp.val()=='手机号/邮箱'){
                oUseP1.css({display:'block'})
            }else {
                if(oBtn1){
                    oBtn1=false;
                    oDuanXinaa1.css({display:'block'});
                    oDuanXinaa2.css({display:'none'});
                    var second=60,
                        iTimer=null;
                    iTimer=setInterval(function daoJiShi(){
                        second--;
                        oDuanXinaa1Em.html(second);
                        if(second==0){
                            clearInterval(iTimer);
                            oDuanXinaa1Em.html(60);
                            oBtn1=true;
                            oDuanXinaa2.css({display:'block'});
                            oDuanXinaa1.css({display:'none'});
                        }
                    },1000)
                }
            }
        });

    //提交按钮的判断
    var
        oBtn = $('.btn>input'),
        oBtnP = $('.btn-p');
    oBtn.click(function() {
        /*不区分大小写*/
        if (oYanZanIp.val().toLocaleLowerCase() != arr1.join('').toLocaleLowerCase()) {
            oBtnP.css({display: 'block'});
            oBtnP.html('请输入正确的验证码');
        }

        //当按钮按下时 设置cookie
        setCookie('useName1', oUseNameIp.val(), 7, '/');
        setCookie('passWard1', oPassWardIp.val(), 7, '/');

        if(oYanZanIp.val().toLocaleLowerCase() == arr1.join('').toLocaleLowerCase()){
            oBtnP.css({display: 'block'});
            oBtnP.html('2秒后自动跳入登录页面 ! ! !');
            setTimeout(function(){
                $(window)[0].location.assign('http://localhost/%E9%AD%85%E5%8A%9B%E6%83%A0%E9%A1%B9%E7%9B%AE/html/Register%20--%E7%99%BB%E5%BD%95%E9%A1%B5%E9%9D%A2.html');
            },2000)
        }
    })



});
